<template>
  <a-spin :spinning="spinning">
    <div class="ipt-row">
      执行时间：每日 <a-input-number v-model="time" placeholder="Basic usage" style="margin:0 10px" /> <a @click="updateReconciliationRuleFun">保存</a>
    </div>
    <div class="table-operator">
      <a-button type="primary" icon="caret-right" :disabled="enable" @click="updateReconciliationRuleFun('start')">启动</a-button>
      <a-button type="primary" icon="pause" :disabled="!enable" @click="updateReconciliationRuleFun('end')">停止</a-button>
    </div>

  </a-spin>
</template>
<script>
import { GetReconciliationRule, updateReconciliationRule } from '@/api/common'
export default {
  data () {
    return {
      enable: false, // 是否启用自动对账
      time: 0, //
      spinning: false
    }
  },
  created () {
    this.GetReconciliationRuleFun()
  },
  methods: {
    GetReconciliationRuleFun () {
      GetReconciliationRule().then(res => {
        if (res.status === 'S000') {
            this.enable = res.data ? res.data.enable : false
            this.time = res.data ? res.data.time : 0
          } else {
            this.$notification.error({
              message: '错误',
              description: res.msg
            })
          }
        console.log(res)
      })
    },
    updateReconciliationRuleFun (updateType = 'time') {
      const reqData = {
        time: this.time
      }
      // 如果是启动和停止
      if (updateType !== 'time') {
        reqData.enable = !this.enable
      }
      this.spinning = true
      updateReconciliationRule(reqData).then(res => {
        this.spinning = false
        if (res.status === 'S000') {
          this.$notification.success({
            message: '保存成功',
            description: res.msg
          })
        } else {
          this.$notification.error({
            message: '错误',
            description: res.msg
          })
        }
      })
    }
  }
}
</script>
<style scoped lang="less">
.ipt-row{
  display: flex;
  align-items: center;
}
.table-operator{
  margin-top: 30px;
}
</style>
